home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent2 / iconv9.lha / IconV9 / examples / roman.icn < prev    next >
Text File  |  1996-05-22  |  588b  |  24 lines

  1. #
  2. #          R O M A N   N U M E R A L S
  3. #
  4.  
  5. #  This program takes Arabic numerals from standard input and writes
  6. #  the corresponding Roman numerals to standard outout.
  7.  
  8. procedure main()
  9.    local n
  10.    while n := read() do
  11.       write(roman(n) | "cannot convert")
  12. end
  13.  
  14. procedure roman(n)
  15.    local arabic, result
  16.    static equiv
  17.    initial equiv := ["","I","II","III","IV","V","VI","VII","VIII","IX"]
  18.    integer(n) > 0 | fail
  19.    result := ""
  20.    every arabic := !n do
  21.       result := map(result,"IVXLCDM","XLCDM**") || equiv[arabic+1]
  22.    if find("*",result) then fail else return result
  23. end
  24.